package com.team5101.config;




import com.team5101.WebZkconfigApplication;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class DriudPoolUtil {

	/**
	 * 获取链接
	 *
	 * @return
	 * @throws SQLException
	 */
	public static Connection getConn() throws SQLException {
		if (WebZkconfigApplication.dataSource == null) {
			throw new RuntimeException("数据源关闭");
		}
		return WebZkconfigApplication.dataSource.getConnection();
	}

	/**
	 * 关闭链接
	 *
	 * @param conn
	 * @param state
	 * @param result
	 */
	public static void close(Connection conn, Statement state, ResultSet result) {

		try {
			if (result != null) {
				result.close();
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			try {
				if (conn != null) {
					conn.close();
				}
			} catch (SQLException e) {
				e.printStackTrace();
			} finally {
				try {
					if (state != null) {
						state.close();
					}
				} catch (SQLException e) {
					e.printStackTrace();
				}
			}
		}
	}


}
